﻿using System;
using System.Collections.Generic;
using Besture.UI.ClassHelper;
using Besture.Utils;
using DevExpress.Web.ASPxGridView;
using DevExpress.Web.Data;
using Besture.Common;
using Besture.Bll;
using Besture.Model;

namespace Besture.UI.Admin.User
{
    public partial class UserList : BasePage
    {
        protected override void InitialLoad()
        {
            BindData();
            AspxGridViewHelper.InitAspxGridView(grid);
        }

        protected override void PostBackLoad()
        {
            BindData();
        }

        /// <summary>
        /// 绑定数据
        /// </summary>
        public void BindData()
        {
            AdminUserDac adminUserDac = new AdminUserDac();
            grid.DataSource = adminUserDac.GetDataTable(new AdminUserModel());
            grid.DataBind();
        }

        protected void grid_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
        {
            if (e.Parameters == "Refresh")
                grid.DataBind();


        }

        /// <summary>
        /// 删除单条数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void grid_RowDeleting(object sender, ASPxDataDeletingEventArgs e)
        {
            e.Cancel = true;
            var ID = Convert.ToInt32(e.Keys[0]);
            AdminUserDac adminUserDac = new AdminUserDac();
            adminUserDac.Delete(ID);
            BindData();
        }

        /// <summary>
        /// 删除选中数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDel_Click(object sender, EventArgs e)
        {
            string ids = AspxGridViewHelper.GetCheckID(grid);
            if (string.IsNullOrEmpty(ids))
            {
                return;
            }
            AdminUserDac adminUserDac = new AdminUserDac();
            adminUserDac.DeleteList(ids);
            BindData();
        }



        protected void btnAdd_Click(object obj, EventArgs eventArgs)
        {
            RedirectUrl("UserSet.aspx");
        }
    }
}